<!-- This comment will put IE 6, 7 and 8 in quirks mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>examples/Supervised/CSvmMaxLikelihoodMS.cpp Source File</title>
<script type="text/javaScript" src="search/search.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3.0.1/es5/tex-mml-chtml.js"></script>
<script src="../../mlstyle.js"></script>
<link href="../css/besser.css" rel="stylesheet" type="text/css"/>
</head>
<!-- pretty cool: each body gets an id tag which is the basename of the web page  -->
<!--              and allows for page-specific CSS. this is client-side scripted, -->
<!--              so the id will not yet show up in the served source code -->
<script type="text/javascript">
    jQuery(document).ready(function () {
        var url = jQuery(location).attr('href');
        var pname = url.substr(url.lastIndexOf("/")+1, url.lastIndexOf(".")-url.lastIndexOf("/")-1);
        jQuery('#this_url').html('<strong>' + pname + '</strong>');
        jQuery('body').attr('id', pname);
    });
</script>
<body>
    <div id="shark_old">
        <div id="wrap">
            <div id="header">
                <div id="site-name"><a href="../../sphinx_pages/build/html/index.html">Shark machine learning library</a></div>
                <ul id="nav">
                    <li >
                        <a href="../../sphinx_pages/build/html/rest_sources/installation.html">Installation</a>
                    </li>
		    <li >
                        <a href="../../sphinx_pages/build/html/rest_sources/tutorials/tutorials.html">Tutorials</a>
                    </li>
		    <li >
                        <a href="../../sphinx_pages/build/html/rest_sources/benchmark.html">Benchmarks</a>
                    </li>
                    <li class="active">
                        <a href="classes.html">Documentation</a>
                        <ul>
                            <li class="first"></li>
                            <li><a href="../../sphinx_pages/build/html/rest_sources/quickref/quickref.html">Quick references</a></li>
                            <li><a href="classes.html">Class list</a></li>
                            <li class="last"><a href="group__shark__globals.html">Global functions</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </div>
<div id="doxywrapper">
<!--
    <div id="global_doxytitle">Doxygen<br>Documentation:</div>
-->
    <div id="navrow_wrapper">
<!-- Generated by Doxygen 1.9.8 -->
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d28a4824dc47e487b107a5db32ef43c4.html">examples</a></li><li class="navelem"><a class="el" href="dir_ca5943d51a26be5f1f9bc4d7d5956bc4.html">Supervised</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">CSvmMaxLikelihoodMS.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="_c_svm_max_likelihood_m_s_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="preprocessor">#include &lt;<a class="code" href="_dataset_8h.html">shark/Data/Dataset.h</a>&gt;</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno">    2</span><span class="preprocessor">#include &lt;<a class="code" href="_c_v_dataset_tools_8h.html">shark/Data/CVDatasetTools.h</a>&gt;</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno">    3</span><span class="preprocessor">#include &lt;<a class="code" href="_data_distribution_8h.html">shark/Data/DataDistribution.h</a>&gt;</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno">    4</span><span class="preprocessor">#include &lt;<a class="code" href="_data_2_statistics_8h.html">shark/Data/Statistics.h</a>&gt;</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno">    5</span><span class="preprocessor">#include &lt;<a class="code" href="_ard_kernel_8h.html">shark/Models/Kernels/ArdKernel.h</a>&gt;</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno">    6</span><span class="preprocessor">#include &lt;<a class="code" href="_quadratic_program_8h.html">shark/Algorithms/QP/QuadraticProgram.h</a>&gt;</span></div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="preprocessor">#include &lt;<a class="code" href="_c_svm_trainer_8h.html">shark/Algorithms/Trainers/CSvmTrainer.h</a>&gt;</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#include &lt;<a class="code" href="_rprop_8h.html">shark/Algorithms/GradientDescent/Rprop.h</a>&gt;</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span><span class="preprocessor">#include &lt;<a class="code" href="_zero_one_loss_8h.html">shark/ObjectiveFunctions/Loss/ZeroOneLoss.h</a>&gt;</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &lt;<a class="code" href="_svm_logistic_interpretation_8h.html">shark/ObjectiveFunctions/SvmLogisticInterpretation.h</a>&gt;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &lt;<a class="code" href="_normalize_components_unit_variance_8h.html">shark/Algorithms/Trainers/NormalizeComponentsUnitVariance.h</a>&gt;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span> </div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="keyword">using namespace </span>std;</div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="keyword">using namespace </span><a class="code hl_namespace" href="namespaceshark.html" title="AbstractMultiObjectiveOptimizer.">shark</a>;</div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span> </div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="comment">// define the basic dimensionality of the problem</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"><a class="line" href="_c_svm_max_likelihood_m_s_8cpp.html#a474fced219be2c88d778a434fe5fc34d">   19</a></span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#a474fced219be2c88d778a434fe5fc34d">useful_dim</a> = 5;</div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"><a class="line" href="_c_svm_max_likelihood_m_s_8cpp.html#a49fd79afb77ad8240bd8d0e6d6f66c5f">   20</a></span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#a49fd79afb77ad8240bd8d0e6d6f66c5f">noise_dim</a> = 5;</div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"><a class="line" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">   21</a></span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a> = <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#a474fced219be2c88d778a434fe5fc34d">useful_dim</a> + <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#a49fd79afb77ad8240bd8d0e6d6f66c5f">noise_dim</a>;</div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span> </div>
<div class="foldopen" id="foldopen00023" data-start="{" data-end="}">
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"><a class="line" href="_c_svm_max_likelihood_m_s_8cpp.html#a28267e6f7ec1120183ffd7ae7a9a60d2">   23</a></span>RealVector <a class="code hl_function" href="_c_svm_max_likelihood_m_s_8cpp.html#a28267e6f7ec1120183ffd7ae7a9a60d2">run_one_trial</a>( <span class="keywordtype">bool</span> verbose) {</div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span> </div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span>        <span class="comment">// set up the classification problem from a DataDistribution</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>    <a class="code hl_class" href="classshark_1_1_pami_toy.html">PamiToy</a> problem( <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#a474fced219be2c88d778a434fe5fc34d">useful_dim</a>, <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#a49fd79afb77ad8240bd8d0e6d6f66c5f">noise_dim</a> );</div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span> </div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span>    <span class="comment">// construct training and test sets from the problem distribution</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> train_size = 500;</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> test_size = 5000;</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span>    <a class="code hl_class" href="classshark_1_1_labeled_data.html">ClassificationDataset</a> train = problem.<a class="code hl_function" href="classshark_1_1_labeled_data_distribution.html#ace15c1b51c87cd4b553427a55416b155" title="Generates a dataset with samples from from the distribution.">generateDataset</a>( train_size );</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>    <a class="code hl_class" href="classshark_1_1_labeled_data.html">ClassificationDataset</a> test = problem.<a class="code hl_function" href="classshark_1_1_labeled_data_distribution.html#ace15c1b51c87cd4b553427a55416b155" title="Generates a dataset with samples from from the distribution.">generateDataset</a>( test_size );</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>    </div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span>        <span class="comment">// normalize data as usual</span></div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>    <a class="code hl_class" href="classshark_1_1_normalizer.html" title="&quot;Diagonal&quot; linear model for data normalization.">Normalizer&lt;&gt;</a> normalizer;</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span>    <a class="code hl_class" href="classshark_1_1_normalize_components_unit_variance.html" title="Train a linear model to normalize the components of a dataset to unit variance, and optionally to zer...">NormalizeComponentsUnitVariance&lt;&gt;</a> normalizationTrainer(<span class="keyword">false</span>);</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span>    normalizationTrainer.<a class="code hl_function" href="classshark_1_1_normalize_components_unit_variance.html#a684b111c701789e332577a6739076c3b">train</a>( normalizer, train.<a class="code hl_function" href="group__shark__globals.html#ga6f74e657c7e0c8a32b2456fb328bd653" title="Access to inputs as a separate container.">inputs</a>() );</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span>    train = <a class="code hl_function" href="group__shark__globals.html#gaf650c7559860ceb0d6b5e3ef3a1be1f3" title="Transforms the inputs of a dataset and return the transformed result.">transformInputs</a>( train, normalizer );</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span>    test = <a class="code hl_function" href="group__shark__globals.html#gaf650c7559860ceb0d6b5e3ef3a1be1f3" title="Transforms the inputs of a dataset and return the transformed result.">transformInputs</a>( test, normalizer );</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>    </div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>        <span class="comment">// set up the ArdKernel</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>    <a class="code hl_class" href="classshark_1_1_a_r_d_kernel_unconstrained.html" title="Automatic relevance detection kernel for unconstrained parameter optimization.">DenseARDKernel</a> kernel( <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>, 0.1 ); <span class="comment">//for now with arbitrary value for gamma (gets properly initialized later)</span></div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>    </div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>        <span class="comment">// set up partitions for cross-validation</span></div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> num_folds = 5;</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>    <a class="code hl_class" href="classshark_1_1_c_v_folds.html">CVFolds&lt;ClassificationDataset&gt;</a> cv_folds = <a class="code hl_function" href="group__shark__globals.html#gac32dddc7b7c3eaa8779dc244c6142eef" title="Create a partition for cross validation.">createCVIID</a>( train, num_folds );</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>    </div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>        <span class="comment">// set up the learning machine</span></div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span>    <span class="keywordtype">bool</span> log_enc_c = <span class="keyword">true</span>; <span class="comment">//use log encoding for the regularization parameter C</span></div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>    <a class="code hl_struct" href="structshark_1_1_qp_stopping_condition.html" title="stopping conditions for quadratic programming">QpStoppingCondition</a> stop(1e-12); <span class="comment">//use a very conservative stopping criterion for the individual SVM runs</span></div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span>    <a class="code hl_class" href="classshark_1_1_svm_logistic_interpretation.html" title="Maximum-likelihood model selection score for binary support vector machines.">SvmLogisticInterpretation&lt;&gt;</a> mlms( cv_folds, &amp;kernel, log_enc_c, &amp;stop ); <span class="comment">//the main class for this tutorial</span></div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>    <span class="comment">//SvmLogisticInterpretation&lt;&gt; mlms( cv_folds, &amp;kernel, log_enc_c ); //also possible without stopping criterion</span></div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>    </div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span>        <span class="comment">// set up a starting point for the optimization process</span></div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>    RealVector start( <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+1 );</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>    <span class="keywordflow">if</span> ( log_enc_c ) start( <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a> ) = 0.0; <span class="keywordflow">else</span> start( <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a> ) = 1.0; <span class="comment">//start at C = 1.0</span></div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>    <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k=0; k&lt;<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>; k++ )</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>        start(k) = 0.5 / <a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>;</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span>    </div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>        <span class="comment">// for illustration purposes, we also evalute the model selection criterion a single time at the starting point</span></div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>    <span class="keywordtype">double</span> start_value = mlms.<a class="code hl_function" href="classshark_1_1_svm_logistic_interpretation.html#a67444886b71f0bef297aaa3d396e6b81">eval</a>( start );</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>    </div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>        <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;Value of model selection criterion at starting point: &quot;</span> &lt;&lt; start_value &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span>        std::cout &lt;&lt; <span class="stringliteral">&quot; -------------------------------------------------------------------------------- &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span>        std::cout &lt;&lt; <span class="stringliteral">&quot; ----------- Beginning gradient-based optimization of MLMS criterion ------------ &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>        std::cout &lt;&lt; <span class="stringliteral">&quot; -------------------------------------------------------------------------------- &quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>    }</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>    </div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>        <span class="comment">// set up the optimizer</span></div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span>    <a class="code hl_class" href="classshark_1_1_rprop.html" title="This class offers methods for the usage of the Resilient-Backpropagation-algorithm with/out weight-ba...">Rprop&lt;&gt;</a> rprop;</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>    <span class="keywordtype">double</span> stepsize = 0.1;</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>    <span class="keywordtype">double</span> stop_delta = 1e-3;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>    mlms.<a class="code hl_function" href="classshark_1_1_abstract_objective_function.html#abe4776a85c4ce622c25f3290fa1395d1">init</a>();</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>    rprop.<a class="code hl_function" href="classshark_1_1_rprop.html#aa5283be5eb772fcdad29af346c98b498">init</a>( mlms, start, stepsize );</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> its = 50;</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>    </div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>        <span class="comment">// start the optimization loop</span></div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>    <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;its; i++) {</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>        rprop.<a class="code hl_function" href="classshark_1_1_rprop.html#a9173edb5b7a84bcd46b62a46445754a6">step</a>( mlms );</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>        <span class="keywordflow">if</span> ( verbose )</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>            std::cout &lt;&lt; <span class="stringliteral">&quot;iteration &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;: current NCLL = &quot;</span> &lt;&lt;  rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#abfb2c7bc8ee3b184bbef15cb250ead50">value</a> &lt;&lt; <span class="stringliteral">&quot; at parameter: &quot;</span> &lt;&lt; rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>        <span class="keywordflow">if</span> ( rprop.<a class="code hl_function" href="classshark_1_1_rprop.html#a7ca10945bb7ef8a73f53512ff25a77a1" title="return the maximal step size component">maxDelta</a>() &lt; stop_delta ) {</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>            <span class="keywordflow">if</span> ( verbose ) std::cout &lt;&lt; <span class="stringliteral">&quot;    Rprop quit pecause of small progress &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>            <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>        }</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>    }</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>    </div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>        <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span>        std::cout &lt;&lt; std::endl;</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>        std::cout &lt;&lt; <span class="stringliteral">&quot; -------------------------------------------------------------------------------- &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>        std::cout &lt;&lt; <span class="stringliteral">&quot; ----------- Done with gradient-based optimization of MLMS criterion ------------ &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>        std::cout &lt;&lt; <span class="stringliteral">&quot; -------------------------------------------------------------------------------- &quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span>    }</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>    <span class="keywordflow">if</span> ( verbose ) std::cout &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot; EVALUATION of hyperparameters found:&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>    </div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>        <span class="keywordtype">double</span> C_reg; <span class="comment">//will hold regularization parameter</span></div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>    <span class="keywordtype">double</span> test_error_v1, train_error_v1; <span class="comment">//will hold errors determined via method 1</span></div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>    <span class="keywordtype">double</span> test_error_v2, train_error_v2; <span class="comment">//will hold errors determined via method 2</span></div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>    </div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>    <span class="comment">// BEGIN POSSIBILITY ONE OF HYPERPARAMETER COPY</span></div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span>        <span class="keywordflow">if</span> ( verbose ) std::cout  &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot; Possibility 1: copy kernel parameters via eval() and C by hand...&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span>    </div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>        <span class="comment">// copy final parameters, variant one</span></div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>    <span class="keywordtype">double</span> end_value = mlms.<a class="code hl_function" href="classshark_1_1_svm_logistic_interpretation.html#a67444886b71f0bef297aaa3d396e6b81">eval</a>( rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a> ); <span class="comment">//this at the same time copies the most recent parameters from rprop to the kernel.</span></div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>    C_reg = ( log_enc_c ? exp( rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a>(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>) ) : rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a>(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>) ); <span class="comment">//ATTENTION: mind the encoding</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>    </div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span>        <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    Value of model selection criterion at final point: &quot;</span> &lt;&lt; end_value &lt;&lt; std::endl;</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    Done optimizing the SVM hyperparameters. The final parameters (true/unencoded) are:&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;        C = &quot;</span> &lt;&lt; C_reg &lt;&lt; std::endl;</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span>        <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>; i++ )</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>            std::cout &lt;&lt; <span class="stringliteral">&quot;        gamma(&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;) = &quot;</span> &lt;&lt; kernel.<a class="code hl_function" href="classshark_1_1_a_r_d_kernel_unconstrained.html#a81946af98e00e545233603f2c66c2cff" title="Return the parameter vector.">parameterVector</a>()(i)*kernel.<a class="code hl_function" href="classshark_1_1_a_r_d_kernel_unconstrained.html#a81946af98e00e545233603f2c66c2cff" title="Return the parameter vector.">parameterVector</a>()(i) &lt;&lt; std::endl;</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span>        std::cout &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot;    (as also given by kernel.gammaVector() : &quot;</span> &lt;&lt; kernel.<a class="code hl_function" href="classshark_1_1_a_r_d_kernel_unconstrained.html#a6bd49c194259cde41c6dd10a0ed40116" title="convenience methods for setting/getting the actual gamma values">gammaVector</a>() &lt;&lt; <span class="stringliteral">&quot; ) &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>    }</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>    </div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>        <span class="comment">// construct and train the final learner</span></div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>    <a class="code hl_struct" href="structshark_1_1_kernel_classifier.html" title="Linear classifier in a kernel feature space.">KernelClassifier&lt;RealVector&gt;</a> svm_v1;</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>    <a class="code hl_class" href="classshark_1_1_c_svm_trainer.html" title="Training of C-SVMs for binary classification.">CSvmTrainer&lt;RealVector&gt;</a> trainer_v1( &amp;kernel, C_reg, <span class="keyword">true</span>, log_enc_c ); <span class="comment">//encoding does not really matter in this case b/c it does not affect the ctor</span></div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span>    <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>        std::cout &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot;    Used mlms.eval(...) to copy kernel.parameterVector() &quot;</span> &lt;&lt; kernel.<a class="code hl_function" href="classshark_1_1_a_r_d_kernel_unconstrained.html#a81946af98e00e545233603f2c66c2cff" title="Return the parameter vector.">parameterVector</a>() &lt;&lt; std::endl;</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    into trainer_v1.parameterVector() &quot;</span> &lt;&lt; trainer_v1.<a class="code hl_function" href="classshark_1_1_abstract_svm_trainer.html#a183757faebfc331f6733946a6ea7de2c" title="get the hyper-parameter vector">parameterVector</a>() &lt;&lt; std::endl;</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    , where C (the last parameter) was set manually to &quot;</span> &lt;&lt; trainer_v1.<a class="code hl_function" href="classshark_1_1_abstract_svm_trainer.html#a7bc3baa63458c785155a231ca73ea483" title="Return the value of the regularization parameter C.">C</a>() &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>    }</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>    trainer_v1.<a class="code hl_function" href="classshark_1_1_c_svm_trainer.html#a9e801518bfba9d02e0749181a5deb0fc" title="Train the C-SVM.">train</a>( svm_v1, train ); <span class="comment">//the kernel has the right parameters, and we copied C, so we are good to go</span></div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>    </div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>        <span class="comment">// evaluate the final trained classifier on training and test set</span></div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>    <a class="code hl_class" href="classshark_1_1_zero_one_loss.html" title="0-1-loss for classification.">ZeroOneLoss&lt;unsigned int&gt;</a> loss_v1;</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>    <a class="code hl_class" href="classshark_1_1_data.html" title="Data container.">Data&lt;unsigned int&gt;</a> output_v1; <span class="comment">//real-valued output</span></div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span>    output_v1 = svm_v1( train.<a class="code hl_function" href="group__shark__globals.html#ga6f74e657c7e0c8a32b2456fb328bd653" title="Access to inputs as a separate container.">inputs</a>() );</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>    train_error_v1 = loss_v1.<a class="code hl_function" href="classshark_1_1_zero_one_loss.html#acba6670d53701d50eed0ecdbc1114175" title="Return zero if labels == predictions and one otherwise.">eval</a>( train.<a class="code hl_function" href="group__shark__globals.html#ga6328a5aa2570c01a5ac5f25076071663" title="Access to labels as a separate container.">labels</a>(), output_v1 );</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>    output_v1 = svm_v1( test.<a class="code hl_function" href="group__shark__globals.html#ga6f74e657c7e0c8a32b2456fb328bd653" title="Access to inputs as a separate container.">inputs</a>() );</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>    test_error_v1 = loss_v1.<a class="code hl_function" href="classshark_1_1_zero_one_loss.html#acba6670d53701d50eed0ecdbc1114175" title="Return zero if labels == predictions and one otherwise.">eval</a>( test.<a class="code hl_function" href="group__shark__globals.html#ga6328a5aa2570c01a5ac5f25076071663" title="Access to labels as a separate container.">labels</a>(), output_v1 );</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span>    <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    training error via possibility 1:  &quot;</span> &lt;&lt;  train_error_v1 &lt;&lt; std::endl;</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    test error via possibility 1:      &quot;</span> &lt;&lt; test_error_v1 &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span>    }</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>        <span class="comment">// END POSSIBILITY ONE OF HYPERPARAMETER COPY</span></div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span> </div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span>    <span class="comment">// BEGIN POSSIBILITY TWO OF HYPERPARAMETER COPY</span></div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span>        <span class="keywordflow">if</span> ( verbose ) std::cout &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot; Possibility 2: copy best parameters via solution().point()...&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>    </div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span>        <a class="code hl_struct" href="structshark_1_1_kernel_classifier.html" title="Linear classifier in a kernel feature space.">KernelClassifier&lt;RealVector&gt;</a> svm_v2;</div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>    <a class="code hl_class" href="classshark_1_1_c_svm_trainer.html" title="Training of C-SVMs for binary classification.">CSvmTrainer&lt;RealVector&gt;</a> trainer_v2( &amp;kernel, 0.1, <span class="keyword">true</span>, log_enc_c ); <span class="comment">//ATTENTION: must be constructed with same log-encoding preference</span></div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span>    trainer_v2.<a class="code hl_function" href="classshark_1_1_abstract_svm_trainer.html#aecde2bab6daf3fa44b94438c7ba79a24" title="set the vector of hyper-parameters">setParameterVector</a>( rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a> ); <span class="comment">//copy best hyperparameters to svm trainer</span></div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>    </div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>        <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    Copied rprop.solution().point = &quot;</span> &lt;&lt; rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    into trainer_v2.parameterVector(), now = &quot;</span> &lt;&lt; trainer_v2.<a class="code hl_function" href="classshark_1_1_abstract_svm_trainer.html#a183757faebfc331f6733946a6ea7de2c" title="get the hyper-parameter vector">parameterVector</a>() &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span>    }</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span>    </div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span>        trainer_v2.<a class="code hl_function" href="classshark_1_1_c_svm_trainer.html#a9e801518bfba9d02e0749181a5deb0fc" title="Train the C-SVM.">train</a>( svm_v2, train );</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span>    </div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno">  154</span>        <span class="comment">// evaluate the final trained classifier on training and test set</span></div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno">  155</span>    <a class="code hl_class" href="classshark_1_1_zero_one_loss.html" title="0-1-loss for classification.">ZeroOneLoss&lt;unsigned int&gt;</a> loss_v2;</div>
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno">  156</span>    <a class="code hl_class" href="classshark_1_1_data.html" title="Data container.">Data&lt;unsigned int&gt;</a> output_v2; <span class="comment">//real-valued output</span></div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno">  157</span>    output_v2 = svm_v2( train.<a class="code hl_function" href="group__shark__globals.html#ga6f74e657c7e0c8a32b2456fb328bd653" title="Access to inputs as a separate container.">inputs</a>() );</div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno">  158</span>    train_error_v2 = loss_v2.<a class="code hl_function" href="classshark_1_1_zero_one_loss.html#acba6670d53701d50eed0ecdbc1114175" title="Return zero if labels == predictions and one otherwise.">eval</a>( train.<a class="code hl_function" href="group__shark__globals.html#ga6328a5aa2570c01a5ac5f25076071663" title="Access to labels as a separate container.">labels</a>(), output_v2 );</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno">  159</span>    output_v2 = svm_v2( test.<a class="code hl_function" href="group__shark__globals.html#ga6f74e657c7e0c8a32b2456fb328bd653" title="Access to inputs as a separate container.">inputs</a>() );</div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno">  160</span>    test_error_v2 = loss_v2.<a class="code hl_function" href="classshark_1_1_zero_one_loss.html#acba6670d53701d50eed0ecdbc1114175" title="Return zero if labels == predictions and one otherwise.">eval</a>( test.<a class="code hl_function" href="group__shark__globals.html#ga6328a5aa2570c01a5ac5f25076071663" title="Access to labels as a separate container.">labels</a>(), output_v2 );</div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno">  161</span>    <span class="keywordflow">if</span> ( verbose ) {</div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno">  162</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    training error via possibility 2:  &quot;</span> &lt;&lt;  train_error_v2 &lt;&lt; std::endl;</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno">  163</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;    test error via possibility 2:      &quot;</span> &lt;&lt; test_error_v2 &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno">  164</span>        std::cout &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot;That&#39;s all folks - we are done!&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>    }</div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno">  166</span>        <span class="comment">// END POSSIBILITY TWO OF HYPERPARAMETER COPY</span></div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno">  167</span> </div>
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno">  168</span>        <span class="comment">// copy the best parameters, as well as performance values into averaging vector:</span></div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno">  169</span>    RealVector final_params(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+3);</div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno">  170</span>    final_params(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>) = C_reg;</div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno">  171</span>    <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>; i++ )</div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno">  172</span>        final_params(i) = rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a>(i)*rprop.<a class="code hl_function" href="classshark_1_1_abstract_single_objective_optimizer.html#a0909596fcc4f80a8d108859b20b64a81" title="returns the current solution of the optimizer">solution</a>().<a class="code hl_variable" href="structshark_1_1_result_set.html#a5afb306cbdabb9ddb962eb22dbf79bb6">point</a>(i);</div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno">  173</span>    final_params(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+1) = train_error_v1;</div>
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno">  174</span>    final_params(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+2) = test_error_v1;</div>
<div class="line"><a id="l00175" name="l00175"></a><span class="lineno">  175</span>    <span class="keywordflow">return</span> final_params;</div>
<div class="line"><a id="l00176" name="l00176"></a><span class="lineno">  176</span>    </div>
<div class="line"><a id="l00177" name="l00177"></a><span class="lineno">  177</span>}</div>
</div>
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno">  178</span> </div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno">  179</span> </div>
<div class="foldopen" id="foldopen00180" data-start="{" data-end="}">
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"><a class="line" href="_c_svm_max_likelihood_m_s_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">  180</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="_c_svm_max_likelihood_m_s_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno">  181</span> </div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span>        <span class="comment">// run one trial with output</span></div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno">  183</span>    <a class="code hl_function" href="_c_svm_max_likelihood_m_s_8cpp.html#a28267e6f7ec1120183ffd7ae7a9a60d2">run_one_trial</a>( <span class="keyword">true</span>);</div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno">  184</span>    std::cout &lt;&lt; <span class="stringliteral">&quot;\nNOW REPEAT WITH 100 TRIALS: now we do the exact same thing multiple times in a row, and note the average kernel weights. Please wait.&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno">  185</span>    </div>
<div class="line"><a id="l00186" name="l00186"></a><span class="lineno">  186</span>        <span class="comment">// run several trials without output, and average the results</span></div>
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno">  187</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> num_trials = 100;</div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno">  188</span>    <a class="code hl_class" href="classshark_1_1_data.html" title="Data container.">Data&lt;RealVector&gt;</a> many_results(num_trials,RealVector(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+3));<span class="comment">//each row is one run of resulting hyperparameters</span></div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno">  189</span>    <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;num_trials; i++ ) {</div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno">  190</span>        many_results.<a class="code hl_function" href="group__shark__globals.html#ga0ea72a74a21d5ff59772516b83c4a58b">element</a>(i) = <a class="code hl_function" href="_c_svm_max_likelihood_m_s_8cpp.html#a28267e6f7ec1120183ffd7ae7a9a60d2">run_one_trial</a>(<span class="keyword">false</span>);</div>
<div class="line"><a id="l00191" name="l00191"></a><span class="lineno">  191</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;.&quot;</span> &lt;&lt; std::flush;</div>
<div class="line"><a id="l00192" name="l00192"></a><span class="lineno">  192</span>    }</div>
<div class="line"><a id="l00193" name="l00193"></a><span class="lineno">  193</span>    std::cout &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><a id="l00194" name="l00194"></a><span class="lineno">  194</span>    </div>
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno">  195</span>        RealVector overall_mean, overall_variance;</div>
<div class="line"><a id="l00196" name="l00196"></a><span class="lineno">  196</span>    <a class="code hl_function" href="namespaceshark.html#ae5ceac5a5be4ad04ada5d528dcb4ec2e" title="Calculates the mean and variance values of the input data.">meanvar</a>( many_results, overall_mean, overall_variance );</div>
<div class="line"><a id="l00197" name="l00197"></a><span class="lineno">  197</span>    <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+1; i++ ) {</div>
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno">  198</span>        std::cout &lt;&lt; <span class="stringliteral">&quot;avg-param(&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;) = &quot;</span> &lt;&lt; overall_mean(i) &lt;&lt; <span class="stringliteral">&quot; +- &quot;</span>&lt;&lt; overall_variance(i) &lt;&lt; std::endl;</div>
<div class="line"><a id="l00199" name="l00199"></a><span class="lineno">  199</span>    }</div>
<div class="line"><a id="l00200" name="l00200"></a><span class="lineno">  200</span>    std::cout &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot;avg-error-train = &quot;</span> &lt;&lt; overall_mean(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+1) &lt;&lt; <span class="stringliteral">&quot; +- &quot;</span>&lt;&lt; overall_variance(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+1) &lt;&lt; std::endl;</div>
<div class="line"><a id="l00201" name="l00201"></a><span class="lineno">  201</span>    std::cout &lt;&lt; <span class="stringliteral">&quot;avg-error-test  = &quot;</span> &lt;&lt; overall_mean(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+2) &lt;&lt; <span class="stringliteral">&quot; +- &quot;</span>&lt;&lt; overall_variance(<a class="code hl_variable" href="_c_svm_max_likelihood_m_s_8cpp.html#af16c93980706ff7c02d0c8d86300d7af">total_dim</a>+2) &lt;&lt; std::endl;</div>
<div class="line"><a id="l00202" name="l00202"></a><span class="lineno">  202</span>    </div>
<div class="line"><a id="l00203" name="l00203"></a><span class="lineno">  203</span>}</div>
</div>
</div><!-- fragment --></div><!-- contents -->
</div>
</body>
</html>
